﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AL100.Samples.Events.Implementation
{
    public partial class frm_Demo : Form
    {
        

        public frm_Demo()
        {
            InitializeComponent();
        }

        private void frm_Demo_Load(object sender, EventArgs e)
        {
            Test_Person_Event();
        }


        private void Test_Person_Event()
        {
            // Appel du constructeur de la classe Person, suivi d'un appel 
            // à un "object initializer".
            Person p = new Person() { Name = "toto", FirstName = "titi" };
            
            p.NameChanged += new NameChangedDelegate(p_NameChanged);
            p.NameChanged2 += new EventHandler<PersonEventArgs>(p_NameChanged2);
            p.Name = "toto";
        }

        void p_NameChanged2(object sender, PersonEventArgs e)
        {
            Append("Event NameChanged fired , New Name :" + e.Name + "," + e.FirstName);       
        }

        void p_NameChanged(object sender, PersonEventArgs e)
        {
            //Person realSender = sender as  Person;

            Append("Event NameChanged fired , New Name :" + e.Name + "," + e.FirstName);    
        }

        private void Append(string text)
        {
            txtLog.Text += text + Environment.NewLine;
        }

       

    }
}
